package easycloud.ecs.provider.model.local;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.InputStream;

import easycloud.ecs.common.domain.Item;
import easycloud.ecs.common.util.Md5Utils;
import easycloud.ecs.provider.model.IStorageObject;

public class LocalStorageObject implements IStorageObject {

	private File file;

	private Item item;

	public LocalStorageObject(File file, Item item) {
		this.file = file;
		this.item = item;
	}

	@Override
	public String getHash() {
		return Md5Utils.computeMD5Hash(file);
	}

	@Override
	public Item getItem() {
		return item;
	}

	@Override
	public String getKey() {
		return item.getPath();
	}

	@Override
	public long getLength() {
		return file.length();
	}

	@Override
	public InputStream getObjectContent() {
		InputStream is = null;
		try {
			is = new FileInputStream(file);
		} catch (FileNotFoundException e) {
		}
		return is;
	}
}
